//
//  TextView.m
//  Test
//
//  Created by lizq on 15/8/17.
//  Copyright (c) 2015年 lizq. All rights reserved.
//

#import "TextView.h"

@interface TextView ()
@property(nonatomic,strong)NSTimer *textTimer;
@property(nonatomic,assign)NSInteger index;
@end
@implementation TextView


// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
    self.index++;
    if(self.index >= self.text.length) {
        [self stopDrawText];
    }
    NSString *sub = [self.text substringToIndex:self.index];
    [sub drawAtPoint:CGPointMake(10, 0) withAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:15],NSForegroundColorAttributeName:[UIColor redColor]}];
}

- (void)stopDrawText {
    if(self.textTimer) {
        [self.textTimer invalidate];
        self.textTimer = nil;
    }
}

- (void)startDrawText {
    self.textTimer = [NSTimer scheduledTimerWithTimeInterval:0.3 target:self selector:@selector(setNeedsDisplay) userInfo:nil repeats:YES];
    self.index = 0;
}
@end
